module.exports = function (app, models, $, db, nm) {
    //新增单品列表
    app.post('/v1/sku',(req,res) => {
        req.body.unitId = req.unitId
        models.sku.insert(req.body, ret => {
            res.send(ret)
        })
    })

    //删除单品列表
    app.delete('/v1/sku',(req,res) => {
        models.sku.remove({_id:req.query._id}, ret => {
            res.send(ret)
        },
            {real:true})
    })

    //修改单品信息
    app.put('/v1/sku',(req,res) => {
        models.sku.update({ _id:req.body._id},req.body, ret => {
            res.send(ret)
        })
    })

    //获取单品列表
    app.get('/v1/sku',(req,res) => {
        var query ={
            pageSize:req.query.pageSize || 10,
            pageNum:req.query.pageNum || 1,
            unitId:req.unitId
        }
        if(req.query.name) query.name = {$regex:req.query.name}
        models.sku.list(query, ret => {
            res.send(ret)
        })
    })

    //获取单品详情
    app.get('/v1/skuInfo',(req,res) => {
        if(req.query._id){
            models.sku.find({_id:req.query._id}, ret => {
                res.send(ret)
            })
        }else{
            res.send({errorMsg:'请传入_id'})
        }
    })

    //搜索单品
    app.get('/v1/skuSear',(req,res) => {
        var query = {
            pageSize:req.query.pageSize || 10,
            pageNum:req.query.pageNum || 1,
            unitId:req.unitId,
            productName:req.query.productName
        }
        models.sku.list(query, ret => {
            res.send(ret)
        })
    }) 
}
